﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagnostics;

namespace UofCASE.AgileProductLinerDSL {
    public partial class TestPortShape {

        public event EventHandler<EventArgs> CollapsingChanged;

        protected override void InitializeInstanceResources() {
            base.InitializeInstanceResources();
        }

        protected override void InitializeShapeFields(IList<ShapeField> shapeFields) {
            CustomExpCollapseField cecField = new CustomExpCollapseField("Sign");
            cecField.DefaultText = global::UofCASE.AgileProductLinerDSL.AgileProductLinerDSLDomainModel.SingletonResourceManager.GetString("TestPortShapeSignDefaultText");
            cecField.DefaultFocusable = false;
            cecField.DefaultAutoSize = true;
            cecField.DefaultAccessibleState = global::System.Windows.Forms.AccessibleStates.Invisible;
            shapeFields.Add(cecField);
        }
        
        protected override void InitializeDecorators(IList<ShapeField> shapeFields, IList<Decorator> decorators) {
            base.InitializeDecorators(shapeFields, decorators);
            
            TextField expCollSignField = (TextField)ShapeElement.FindShapeField(shapeFields,"Sign");
            if (expCollSignField != null) {
                expCollSignField.AnchoringBehavior.Clear();
                expCollSignField.AnchoringBehavior.SetLeftAnchor(AnchoringBehavior.Edge.Left, 0.01);
                expCollSignField.AnchoringBehavior.SetRightAnchor(AnchoringBehavior.Edge.Right, 0.01);
                expCollSignField.AnchoringBehavior.SetTopAnchor(AnchoringBehavior.Edge.Top, 0.01);
                expCollSignField.AnchoringBehavior.SetBottomAnchor(AnchoringBehavior.Edge.Bottom, 0.01);
                expCollSignField.AnchoringBehavior.CenterHorizontally();
            }
        }

        public override bool CanSelect {
            get {
                return false;
            }
        }

        public override bool CanMove {
            get {
                return false;
            }
        }

        public override void OnMouseDown(DiagramMouseEventArgs e) {
            e.DiagramClientView.Selection.Clear();
            ChangeCollapsing();
        }

        public void ChangeCollapsing(){
            using (Transaction t = this.Store.TransactionManager.BeginTransaction("Collapsing/Extending tests")) {
                this.IsCollapsed = !this.IsCollapsed;
                CollapsingChanged(this, new EventArgs());
                t.Commit();
            }
        }
    }
}
